<?php

namespace Biz\model\brandIndex;

use Doraemon\pockets\datebase\BaseDbModel;

class BrandMsg extends BaseDbModel
{

    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_store';

    const _DATABASE_ = 'hhz_store';

    const _TABLE_NAME = 'brand_msg';

    const STATUS_NORMAL = 1;
    const STATUS_DELETE = 9;
    const STATUS = [
        self::STATUS_NORMAL => '正常',
        self::STATUS_DELETE => '删除'
    ];

    const MSG_SOURCE_BASIC = 1;
    const MSG_SOURCE_CONTENT = 2;
    const MSG_SOURCE_SHOP = 3;
    const MSG_SOURCE_H5 = 4;
    const MSG_SOURCE_RANKING = 5;//榜单
    const MSG_SOURCE_BLIND_BOX = 6;//超级盲盒
    const MSG_SOURCE_GOODS_TEST = 7;//好物轻测

    const MSG_TYPE_PASS = 1;//通过
    const MSG_TYPE_OVER = 2;//不通过

    const PAGESIZE = 20;

    public static function getMsgsByBrandId($start = 0, $limit = self::PAGESIZE, $brand_id = 0)
    {
        if ($brand_id) {
            return self::select('*', [
                "brand_id" => $brand_id,
                "msg_status" => self::STATUS_NORMAL,
                "ORDER" => [
                    "addtime" => "DESC"
                ],
                "LIMIT" => [$start, $limit]
            ]);
        }
        return [];
    }

    public static function getMaxMsgIdByBrandId($brand_id = 0)
    {
        if ($brand_id) {
            return (int)self::max('id', [
                "brand_id" => $brand_id,
                "msg_status" => self::STATUS_NORMAL
            ]);
        }
    }

    public static function getMsgCountByBrandId($brand_id = 0)
    {
        if ($brand_id) {
            return (int)self::count([
                "brand_id" => $brand_id,
                "msg_status" => self::STATUS_NORMAL,
                "ORDER" => [
                    "addtime" => "DESC"
                ]
            ]);
        }
    }

    //添加
    public static function addData($data)
    {
        self::insert($data);
        return self::id();
    }

    //修改
    public static function editData($data, $where = [])
    {
        if (!$where) {
            return false;
        }
        return self::update($data, $where);
    }

}

